"""
FileName：yaml_utils.py
Description：
Author：gaojiahui
Time：2025/8/15 11:00
Website：https://gitee.com/gao-jiahui
"""
import os.path

import yaml

"""YAML数据读取工具类"""
class YamlDataLoader:
    def __init__(self,file_path):
        self.file_path = file_path

    def load_data(self):
        """加载YAML数据"""
        if not os.path.exists(self.file_path):
            raise FileNotFoundError(f"YAML文件不存在:{self.file_path}")

        with open(self.file_path,'r',encoding='utf-8') as file:
            return yaml.safe_load(file)

    def get_test_cases(self,category):
        """获取指定类别的测试用例"""
        data = self.load_data()
        return data.get(category,[])

    def get_all_categories(self):
        """获取所有数据类别"""
        data = self.load_data()
        return list(data.keys())

# 使用示例
user_loader = YamlDataLoader("test_data/user_management.yml")
create_cases = user_loader.get_test_cases("create_user")